<?
// $_REQUEST= $_POST + $_GET

// default value
if (!array_key_exists('date',$_REQUEST) || is_null($_REQUEST['date']))
	$_REQUEST['date']= date('m/d/Y');

$errors= array();
if (isset($_REQUEST['submitted'])) {
	// conversion
	try {
		$date= new DateTime($_REQUEST['date']);
		//validation
		if ($date->format('U')<= time()) $errors[]= 'Date is in the past.';
		else {
			// formatting
			echo('Sent date: '.$date->format('d/m/Y'));
		}
	}
	catch (Exception $e) {
		$errors[]= 'Invalid date.';
	}
}

// INPUT mask
?>
<h2>Please enter following fields</h2>

<ul>
<? foreach ($errors as $error) { ?>
	<li><?= $error; ?></li>
<? } ?>
</ul>

<form>
	<input type="hidden" name="submitted" value="true" />
	<span>Date:</span>
	<input type="text" name="date" value="<?= $_REQUEST['date']; ?>" />
	<input type="submit" value="Submit" />
</form>
